package jp.tkym.labs.geom;

public class Vector3f {
	public float x, y, z;
	
	public Vector3f(){
		this(0.0f, 0.0f, 0.0f);
	}
	
	public Vector3f(float x, float y, float z){
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	public Vector3f diff(Vector3f a){
		this.x -= a.x;
		this.y -= a.y;
		this.z -= a.z;
		return this;
	}
	
	public Vector3f add(Vector3f a){
		this.x += a.x;
		this.y += a.y;
		this.z += a.z;
		return this;
	}
	
	public Vector3f direct(){
		float l = length();
		return new Vector3f(this.x/l, this.y/l, this.z/l);
	}
	
	public float length(){
		return (float) Math.sqrt(inner(this));
	}
	
	public float inner(Vector3f a){
		return this.x*a.x + this.y*a.y + this.z * a.z;
	}
	
	public Vector3f clone(){
		return new Vector3f(this.x, this.y, this.z);
	}
	
	public Vector3f multiply(Matrix3f left){
		Vector3f r  = this.clone();
		this.x = left.getRow(0).inner(r);
		this.y = left.getRow(1).inner(r);
		this.z = left.getRow(2).inner(r);
		return this;
	}

	@Override
	public String toString() {
		return "Vector3f:[" + x + ", " + y + ", " + z + "]";
	}
}